package com.yhj.config;

import com.yhj.handler.Handler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @author yaohj
 * @date 2025年02月05日 10:44
 */
@Configuration
public class HandlerChainConfig {
    @Autowired
    private List<Handler> handlers;

    @Bean
    public Handler handlerChain() {
        if(handlers==null||handlers.size()==0){
            return null;
        }
        //构建责任链关系
        for(int i =0 ;i<handlers.size()-1;i++){
            handlers.get(i).setNext(handlers.get(i+1));
        }

        return handlers.get(0);
    }
}
